/*给相应的链接添加地址*/
var allBuildQALink = function(record) {
    //WebSite.debug(record.status);
    var status=record.status;
    var pk_question=record.pk_sool_question;
    var pk_answer_user = record.pk_answer_sool_user;

    if (status == WebSite.askerWaitToAnswerStatus) {
        //提问者待解答
        return WebSite.AskerUnansweredPage.url + "&pk_question="+pk_question;
    } else if (status == WebSite.askerWaitToHandle) {
        //提问者待处理
        return WebSite.AskerHandlingPage.url + "&pk_question="+pk_question+"&pk_answer_user="+pk_answer_user;
    } else {
        //提问者已解决
        return WebSite.AskerSolvedPage.url + "&pk_question="+pk_question;
    }
};

/*加载全部问题*/
var findAll = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    $.ajax({
        url:WebSite.MyQuestionListPage.myquestion_list_pageno,
        type:"POST",
        data: {"pageno" : pageno,"methodname":'findAll'},
        dataType:"json",
        success:function(resulData){
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myQuestionList").html(myTemplate(data));
        },
    });
};

/*待解答加载*/
var tobeanswered = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "status": 1
    }, true);
    $.ajax({
        url: WebSite.MyQuestionListPage.myquestion_stuts1list_pageno + "&" + params,
        type: "POST",
        data: {"pageno" : pageno,"methodname":'tobeanswered'},
        dataType: "json",
        success: function (resulData) {
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myQuestionList").html(myTemplate(data));
        },
        error: function () {}
    });
}

/*待处理*/
var pending = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "status":2
    },true);
    $.ajax({
        url: WebSite.MyQuestionListPage.myquestion_stuts2list_pageno + "&" + params,
        type: "POST",
        data: {"pageno" : pageno,"methodname":'pending'},
        dataType: "json",
        success: function (resulData) {
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myQuestionList").html(myTemplate(data));
        },
        error: function () {}
    });
}

/*已解决加载*/
var alreadysolved = function(pageno){
    if(pageno == null){
        pageno = 1;
    }
    var params = $.param({
        "status":3
    },true);
    $.ajax({
        url: WebSite.MyQuestionListPage.myquestion_stuts3list_pageno + "&" + params,
        type: "POST",
        data: {"pageno" : pageno,"methodname":'alreadysolved'},
        dataType: "json",
        success: function (resulData) {
            var data = resulData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                record.qa_link = allBuildQALink(record);
            }
            var pagemess=resulData.pagemess;
            $('#pagemes').html(pagemess);
            var myTemplate = Handlebars.compile($("#article_template").html());
            $("#myQuestionList").html(myTemplate(data));
        },
        error: function () {}
    });
}

/*精华问题加载*/
var similarQuestion = function(){
    $.ajax({
        url:WebSite.MyQuestionListPage.essencequestion_list,
        type:"POST",
        data:{"count":10},
        dataType:"json",
        success:function(resultData){
            var data = resultData.resultData;
            for (var i = 0, len = data.length; i < len; i++) {
                var record = data[i];
                var pk_sool_question = record.pk_sool_question;
                record.qa_link = WebSite.AskerSolvedPage.url + "&pk_question="+pk_sool_question;
            }
            var myTemplate = Handlebars.compile($("#li_template").html());
            $("#xsQuestionList").html(myTemplate(data));
        },
        error:function(){
            alert("相似问题未加载");
        }
    });

};

/*根据对应的锚点加载不同的内容*/
var queryDataByStatus = function() {
    var status_type = window.location.hash;
    WebSite.debug("queryDataByStatus这个方法："+status_type);
    if (status_type == "#s0") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-all").toggleClass("am-active");
        findAll();
    }
    else if (status_type == "#s1") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-unanswer").toggleClass("am-active");
        tobeanswered();
    }  else if (status_type == "#s2") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-handling").toggleClass("am-active");
        pending();
    }  else if (status_type == "#s3") {
        $("#subMyQuestionList li").removeClass("am-active");
        $("#a-solved").toggleClass("am-active");
        alreadysolved();
    }
};

/*点击相似问题的三级页面*/
var xxsMyQuestion = function(){
    var pk_sool_question=$(this).attr("pk_sool_question");
    window.location.href = WebSite.AskerSolvedPage.url+"&pk_sool_question="+pk_sool_question;
};

/*格式化时间*/
Handlebars.registerHelper("transdate", function(str,options){
    return new Date(parseInt(str)).toLocaleString();
});































